<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <!--edge浏览器H5兼容设置-->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!--360浏览器H5兼容设置-->
    <meta name="renderer" content="webkit" />
    <title>个人信息修改</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!--导入核心文件-->
    <script src="../bootstrap3/js/holder.js"></script>
    <link href="../bootstrap3/css/bootstrap.css" rel="stylesheet" type="text/css">
    <script src="../bootstrap3/jquery-1.9.1.min.js"></script>
    <script src="../bootstrap3/js/bootstrap.js"></script>
    <!-- 字体图标 -->
    <link rel="stylesheet" href="../bootstrap3/font-awesome-4.7.0/css/font-awesome.css" />

    <script src="../bootstrap3/js/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
    <link rel="stylesheet" type="text/css" href="../css/update.css"/>
</head>
<body>
<!--网页最上方的留白-->
<header>
    <!-- class.container 容器定位 的作用是进行居中布局 -->
    <div class="container">
        <!-- pull-right 向右对齐  -->
        <span class="pull-right"><small>Sports  Equipment</small> <b>Management</b>System</span>

    </div>
</header>
<!--网页 导航栏 在layout.css 文件中设置背景图片-->
<nav>
    <!-- class.container 容器定位 用于设置内容居中 -->
    <div class="container">
        <h1>
            <b>体育器材管理系统</b> <small>——Design by Z</small>
        </h1>
        <!--导航栏-->
        <div>
            <!-- class="nav navbar-nav" 定义导航条 -->
            <ul class="nav nav-pills navbar-left">
                <li><a href="home.html">首页</a></li>
            </ul>
            <!-- class="nav navbar-nav" 定义导航条 向右侧浮动 -->
            <ul class="nav nav-pills navbar-right">
                <!-- 导航条中的文字使用 class="navbar-text" 样式 -->
                <li><span class="navbar-text"></span></li>
                <li><a id="loginout"><span class="glyphicon glyphicon-off" aria-hidden="true"></span></a></li>
            </ul>
        </div>
        <!-- /导航栏 -->
    </div>
</nav>
<section>
    <br>

    <div class="container">
        <div class="row">
            <div class="col-md-8"></div>
            <div class="col-md-4">

                <form id="form-info" class="form-horizontal" role="form">
                    <p>信息修改：<span id="username">???</span></p>
                    <hr>
                    <div class="form-group">
                        <label class="col-md-3 col-sm-3 control-label" for="OldPassword">原密码：</label>
                        <div class="col-md-8 col-sm-8">
                            <input type="text" class="form-control" id="OldPassword" name="oldPassword" placeholder="请输入您的原密码" >
                        </div>

                    </div>
                    <div class="form-group">
                        <label  class="col-md-3 col-sm-3 control-label" for="NewPassword">新密码：</label>
                        <div class="col-md-8 col-sm-8">
                            <input type="text" class="form-control" id="NewPassword" name="newPassword" placeholder="请输入您的新密码" >
                        </div>

                    </div>
                    <div class="form-group">
                        <label class="col-md-3 col-sm-3 control-label" for="phone">手机号：</label>
                        <div class="col-md-8 col-sm-8">
                            <input type="text" class="form-control" id="phone" name="phone" placeholder="请输入您的手机号码" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 col-sm-3 control-label" for="email">邮箱：</label>
                        <div class="col-md-8 col-sm-8">
                            <input type="text" class="form-control" id="email" name="email" placeholder="请输入您的邮箱" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-md-4 col-sm-4 control-label" for="btn-info"></label>
                        <div class="col-md-8 col-sm-8">
                            <input id="btn-info" class="btn btn-primary" type="button" value="确认修改">
                        </div>
                    </div>
                </form>
            </div>

        </div>
    </div>
    <br>
</section>
<!--页脚开始-->
<!--网页底部， class.well 用于设置背景效果-->
<footer class="well">
    <!-- class.container 的作用是进行居中布局 -->
    <div class="container">
        <b>Copyright © 2020 ？？.com All Rights Reserved
            <a href="#">啥也不是</a>
            版权所有
        </b> <span class="pull-right"> <b>Version</b> 1.1.0
      </span>
    </div>
</footer>
<!--页脚结束-->
<script src="../bootstrap3/jquery-1.9.1.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $.ajax({
                "url":"/users/showupdate",
                "type":"get",
                "dataType":"json",

                success:function (json) {
                    console.log(json.data)
                    if (json.data!=null){

                        $("#phone").val(json.data.phone)
                        $("#username").text(json.data.username)
                        $("#email").text(json.data.email)
                        $("#btn-info").removeAttr("disabled")
                        $(".navbar-text").text("管理员："+json.data.num)
                    }
                },
                "error":function () {
                    $("input").attr("disabled",true)
                    $("#ul").prepend($('<li><a href="' +'http://localhost:8080/web/login.html'+ '">'+"登录"+'</a></li>'))
                    $(".navbar-text").text(" ")
                }



            });
        })


        $("#loginout").bind('click',function () {
            $.ajax({
                "url":"/users/logininfo",
                "type":"get",
                "dataType":"json",
                success:function (json) {
                    if(json.state==2000){
                        window.location.href="login.html"
                    }
                },
                "error":function () {

                    $(".navbar-text").append($('<a href="' +'http://localhost:8080/web/login.html'+ '">'+"登录"+'</a>'))

                }
            })
        })

        $("#btn-info").click(function() {
            $.ajax({
                "url":"/users/updateInfo",
                "data":$("#form-info").serialize(),
                "type":"post",
                "dataType":"json",
                "success":function(json) {
                    if (json.state == 2000) {
                        alert("修改成功！");
                        $("#form-info")[0].reset();
                         location.href = "login.html";
                    } else {
                        alert(json.message);
                    }
                },
                "error":function(xhr) {
                    alert("您的登录信息已经过期，请重新登录！"
                        + "\n\nHTTP响应码：" + xhr.status);
                    // location.href = "login.html";
                }
            });
        });
</script>


</body>
</html>